<?php
namespace Futures\Controller;
use Think\Controller;
use Think\FuturesPage;
class TransactionController extends BaseController{
	public function index(){
		$user_auth= cookie('user_auth');
        $user_id=$user_auth['uid'];
        $where_number['user_id']=array('eq',$user_id);
        $where_number['status']=array('eq',2);
        $total_money=M('futures_order')->where($where_number)->sum('profit');//总盈亏
        $total_number=M('futures_order')->where($where_number)->sum('number');//总手数
        $total_number_one=M('futures_order')->where($where_number)->count('id');//总单数
        $count=M('futures_order')->where($where_number)->count();
        $per_num    = 10;//每页条数    自定义
        $Page       = new FuturesPage($count,$per_num);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        //$Page->lastSuffix = false;//最后一页不显示为总页数
        $Page->setConfig(array());
        $show       = $Page->show();// 分页显示输出
        $pages      = ceil($count/$per_num);//总页数
        $this->assign('page',$show);
       	
       	$list = M('futures_order')->where($where_number)->order('create_time desc')->limit($Page->firstRow.','.$Page->listRows)->select();
       	foreach($list as $k=>$v){
			$list[$k]['create_time']=date('Ymd',$v['begin_time']);
			//获取商品名称
			$where_futures['id']=$v['futures_id'];
			$futures_name=M('futures')->where($where_futures)->getField('name');
			$list[$k]['name']=$futures_name;
		}
       	$url = U('Transaction/index','','');
        $this->assign('url',$url);
        $this->assign('total_money',$total_money);
        $this->assign('total_number',$total_number);
        $this->assign('total_number_one',$total_number_one);
		$this->assign('list',$list);
		$this->display();
	}
}
?>